/*
 * @Author: jianfanfan 1217572833@qq.com
 * @Date: 2025-03-19 16:56:32
 * @LastEditors: jianfanfan 1217572833@qq.com
 * @LastEditTime: 2025-03-25 19:46:39
 * @FilePath: \guozaoke\src\node\entities\node.entity.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToMany,
  TreeChildren,
  TreeParent,
  TreeLevelColumn,
} from 'typeorm';
import { Post } from './post.entity';

@Entity()
export class Node {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: '节点ID',
  })
  id: number;

  @Column({
    type: 'varchar',
    length: 50,
    comment: '节点名称',
  })
  name: string;

  @Column({
    type: 'varchar',
    length: 50,
    comment: 'URL友好的标识符',
  })
  slug: string;

  @TreeChildren()
  children: Node[];

  @TreeParent()
  parent: Node;

  @TreeLevelColumn()
  depth: number;

  @Column({
    type: 'varchar',
    length: 200,
    comment: '节点描述',
  })
  description: string;

  @Column({
    type: 'int',
    comment: '父节点ID，null表示顶级节点',
    nullable: true
  })
  parentId: number | null;

  @Column({
    type: 'int',
    default: 0,
    comment: '排序权重，数值越大越靠前',
  })
  sort: number;

  @OneToMany(() => Post, (post) => post.node)
  posts: Post[];

  @Column({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    comment: '创建时间',
  })
  createTime: Date;

  @Column({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
    comment: '更新时间',
  })
  updateTime: Date;
}
